package mipo.top.pet.controller;

import mipo.top.base.util.JsonResult;
import mipo.top.base.util.PageUtil;
import mipo.top.pet.Service.IPetDetailService;
import mipo.top.pet.domain.PetDetail;
import mipo.top.pet.query.PetDetailQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/petdetail")
public class PetDetailController {

    @Autowired
    private IPetDetailService petDetailService;

    @GetMapping
    public List<PetDetail> sad(){
        return petDetailService.findall();
    }

    @PutMapping
    public JsonResult su(@RequestBody PetDetail petDetail){
        try {
            if(petDetail.getId()==null){
                petDetailService.save(petDetail);
            }else{
                petDetailService.update(petDetail);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("错误数据");
        }
    }

    @DeleteMapping("/{id}")
    public void adw(@PathVariable("id") Long id){
        petDetailService.remove(id);
    }
    @GetMapping("/{id}")
    public PetDetail findone(@PathVariable("id") Long id){
      return petDetailService.findone(id);
    }

    @PostMapping
    public PageUtil<PetDetail> asp(@RequestBody PetDetailQuery petDetailQuery){
        return petDetailService.queryData(petDetailQuery);
    }
    @PatchMapping
    private void bacthDel(@RequestBody List<Long> ids){
        petDetailService.patchremove(ids);
    }
}
